<?php 
class EmployeeHandler{

private $empsearch;
private $fn;
private $con;

public function setEmp($emp){

$this->empsearch=$emp;

}

public function setFn($fnn){

$this->fn=$fnn;

}
public function setCon($conn){

$this->con=$conn; 

}


//Adding employee details to database

public function employeeAdd($ini,$fn,$ln,$gen,$bdy,$nic,$add,$cont,$email,$jdy,$quali,$exe,$cat){
		
$sql1="insert into employee(initials,f_name,l_name,gender,b_date,nic,address,tel_no,email,j_date,qualifications,exp,category)      values('$ini','$fn','$ln','$gen','$bdy','$nic','$add','$cont','$email','$jdy','$quali','$exe','$cat')";

mysql_query($sql1,$this->con) or 
die(mysql_error());
$msg="Succefully added";
return $msg;
}





public function getPageSearch($startrow,$limit){

$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee order by emp_no desc  Limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
 
 }



public function getSearch($startrow,$empsearch,$fn,$limit){ 

if($fn=="emp"){

$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where emp_no like '$empsearch%' limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
 
 

} else if($fn=="fn"){

$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where f_name like '$empsearch%' limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;


}else {
$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where l_name like '$empsearch%'limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;

}

}




public function getPaginationRow($empsearch,$fn){ 

if($fn=="emp"){

$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where emp_no like '$empsearch%'";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;

}

else if($fn=="fn"){

$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where f_name like '$empsearch%' ";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;


}else{ 
$sql="select emp_no,f_name,l_name,gender,tel_no,category from employee where l_name like '$empsearch%'";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}


}



public function getDelete($id){

$sql="DELETE FROM employee WHERE emp_no='$id'";
mysql_query($sql,$this->con) or die(mysql_error());  ;

$msgd="Deleted";
return $msgd;
}



public function employeeUpdate($empno,$ini,$fn,$ln,$gen,$bdy,$nic,$add,$cont,$email,$jdy,$quali,$exe,$cat){

$sql="update employee set initials ='$ini',f_name='$fn',l_name='$ln',gender='$gen',b_date='$bdy',nic='$nic',address= '$add',tel_no='$cont',email='$email',j_date='$jdy', qualifications='$quali', exp='$exe', category='$cat' where emp_no='$empno'"; 		
		
mysql_query($sql,$this->con) or 
die(mysql_error());
$msg =" Record Successfully updated";
return $msg;	
		
}



public function getReport($empno){

$sql="select * from employee where emp_no='$empno'";
$result=mysql_query($sql,$this->con);
return $result;

}

}



?>